﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Mmht.BT;

public partial class reader : BasePage
{
    GetPdf gp = new GetPdf();
    GetPdf getPdf = new GetPdf();
    public string pdfUrl;
    public int id = 0;
    public DataRow pdfDetail;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["type"] == null)
        {
            Response.Redirect("login.aspx");
            return;
        }
        if (!IsPostBack)
        {
            if (Request["id"] != null)
            {
                id = int.Parse(Request["id"]);
                this.getPdfDetail(id);
                ViewNumberBT vn = new ViewNumberBT();
                vn.addPdfViewNum(id);
            }
        }
        controlRepeater();
    }
    private void controlRepeater()
    {
        DataTable table1 = getPdf.Get_Recommended_Pdf("课件");
        DataTable table3 = getPdf.Get_CTRtop_Pdf("课件", 9);

        this.Repeater1.DataSource = table3;
        this.Repeater1.DataBind();

        this.Repeater3.DataSource = table1;
        this.Repeater3.DataBind();
    }

    public string getViewHostClass(Object number)
    {
        return ViewHotBT.getViewHostClass(number);
    }

    private void getPdfDetail(int id)
    {
        pdfDetail = gp.GetPdfById(id);
        if (pdfDetail == null)
        {
            pdfUrl = string.Empty;
            return;
        }
        pdfUrl = pdfDetail["pdf_url"].ToString();
    }

    /// <summary>
    /// 没用
    /// </summary>
    /// <param name="url"></param>
    private void pdf_read(string url)
    {
        string p = url;
        //p = "2.doc";
        //p = "3.xls";
        string url1 = Request.Url.ToString();
        string[] tags = url1.Split('/');
        string url2 = tags[tags.Length - 1];
        string filePath = url1.Replace(url2, "files/pdf/" + p);
        //string filePath = Server.MapPath("DataFile/" + p);//转换为物理路径
        Response.ClearContent();//清空缓冲区内容
        Response.ClearHeaders();//清空缓冲区HTTP头
        string FilePost = filePath.Substring(filePath.Length - 3).ToLower();//取扩展名
        switch (FilePost)
        {
            case "pdf"://PDF文件
                Response.ContentType = "application/PDF";//设置HTTP头为PDF文档其它类似
                break;
            case "doc":
                Response.ContentType = "application/msword";
                break;
            case "xls":
                Response.ContentType = "application/vnd.ms-excel";
                break;
            default:
                Session["ErrorInfo"] = "不支持的文件格式:" + FilePost;
                Response.Redirect("ErrorPage.aspx");
                break;
        }
        filePath = url;
        Response.WriteFile(filePath);//写入客户端
        Response.Flush();//客户更新
        Response.Close();//写入关闭
        Session.Remove("Report");//移除"Report"Session

    }
}
